import axios from 'axios';

const GLOBAL_STORE = 'globalStore';

let local_lang;
if(localStorage.getItem('lang')){
    local_lang = localStorage.getItem('lang');
}

export const state = () => ({
    userName: '',
    developerId: '',
    account: '',
    localLang: local_lang || 'MM',
    regionId: '',
    isLogin: false,
    chatMsgNumber: '',
    chatLoginStatus: false,
    subjectDetail: {
        show: false,
        imgUrl: '',
        title: '',
        priceType: '',
        price: '',
        goodsId: ''
    }
});

export const mutations = {
    updateSubjectDetail(state, payload){
        state.subjectDetail = payload
    },
    updateUserName (state, payload) {
        state.userName = payload
    },
    updateDeveloperId (state, payload) {
        state.developerId = payload
    },
    updateAccount (state, payload) {
        state.account = payload
    },
    updateLang (state, payload) {
        state.localLang = payload
    },
    updateRegionId(state, payload){
        state.regionId = payload
    },
    updateIsLogin(state, payload){
        state.isLogin = payload
    },
    updateChatMsgNumber(state, payload){
        state.chatMsgNumber = payload
    },
    updateChatLoginStatus(state, payload){
        state.chatLoginStatus = payload
    }
};

export const actions = {
    // async setWeather({commit}, params) {
    //     try {
    //         let url = `https://query.yahooapis.com/v1/public/yql?q=select%20item.condition%20from%20weather.forecast%20where%20woeid%20%3D%20${params.woeid}&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys`;
    //         let result = await axios(url);
    //
    //         let condition = result.data.query.results.channel.item.condition;
    //
    //         commit(SET_WEATHER, {
    //             weatherText: condition.text,
    //             weatherTemp: condition.temp
    //         })
    //     }
    //     catch (e) {
    //         // TODO with error
    //         console.log('error in setWeather');
    //         console.log(e);
    //     }
    // }
};
